<div xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:rich="http://richfaces.org/rich">

  <c:if test="#{tagServiceEnabled}">

    <c:set var="ajaxReRender" value="#{widgetProperty_ajaxReRender}" />

    <c:if test="#{widget.handlingLabels}">
      <c:if test="#{!empty widget.label}">
        <ui:include src="/widgets/incl/widget_label_template.xhtml">
          <ui:param name="labelStyleClass"
            value="summaryTitle #{widgetProperty_headerStyleClass}" />
        </ui:include>
      </c:if>
      <c:if test="#{empty widget.label}">
        <ui:include src="/widgets/incl/label_template.xhtml">
          <ui:param name="label" value="action.view.tagging" />
          <ui:param name="helpLabel" value="#{widget.helpLabel}" />
          <ui:param name="translated" value="true" />
          <ui:param name="required" value="#{widget.required}" />
          <ui:param name="labelStyleClass"
            value="summaryTitle #{widgetProperty_headerStyleClass}" />
        </ui:include>
      </c:if>
    </c:if>

    <a4j:jsFunction name="listDocumentsForTag"
      action="#{tagSelect2Support.listDocumentsForTag}">
      <a4j:param name="param1" assignTo="#{tagSelect2Support.label}" />
    </a4j:jsFunction>

    <a4j:jsFunction name="addTagging"
      render="#{ajaxReRender}"
      action="#{tagSelect2Support.addTagging}">
      <a4j:param name="param1" assignTo="#{tagSelect2Support.label}" />
    </a4j:jsFunction>

    <a4j:jsFunction name="removeTagging"
      render="#{ajaxReRender}"
      action="#{tagSelect2Support.removeTagging}">
      <a4j:param name="param1" assignTo="#{tagSelect2Support.label}" />
    </a4j:jsFunction>

    <ui:include src="/incl/select2_js.xhtml" />

    <a4j:region>
      <h:inputHidden id="#{widget.id}_select2" value="#{documentTagIds}">
        <f:converter converterId="select2Converter" />
      </h:inputHidden>
      <h:inputHidden readonly="true" id="#{widget.id}_select2_init"
        value="#{resolveDocumentTags}" />
    </a4j:region>

    <h:inputHidden readonly="true" id="#{widget.id}_select2_params"
      value="#{tagSelect2Support.encodeParametersForCurrentDocument(widgetProperties)}" />

  </c:if>

</div>